package com.qk.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.commom.PageResult;
import com.qk.entity.Dept;
import com.qk.mapper.DeptMapper;
import com.qk.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    /**
     * 新增部门
     */
    @Override
    public void addDept(Dept dept){
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept) ;
    }

    /**
     * 部门列表
     */
    @Override
    public PageResult<Dept> listDepts(String name, Integer status, Integer page, Integer pageSize){
        PageHelper.startPage(page, pageSize);
        List<Dept> depts = deptMapper.listDepts(name, status);
        Page<Dept> pageInfo =( Page<Dept>) depts;
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getResult());




    }
    @Override
    public Dept getById(Integer id){
        return deptMapper.getById(id);
    }


    @Override
    public void update(Dept dept){
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }

    @Override
    public void deleteById(Integer id){
        deptMapper.deleteById(id);
    }

    @Override
    public List<Dept> listAll( Integer  status){
        return deptMapper.listAll( );
    }
}
